#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

class Solution {
public:

    int searchInsert(vector<int>& nums, int target) {
        int n = nums.size();
        int left = 0, right = 0, mid = 0;
        right = n - 1;
        int found = 0;
        while (left <= right) {
            mid = (left + right) / 2;
            printf("left :%d  right:%d  mid : %d\n", left,right, mid);
            if (nums[mid] > target) {
                right = mid - 1;
            } else if (nums[mid] < target) {
                left = mid + 1;
            } else {
                left = mid;
                found = 1;
                break;
            }
        }
        if (found) {
            printf("Find %d exists \n", target);
        } else {
            printf("Find %d doesn't exists \n", target);
        }
        return left;
    }
};

int main()
{
    vector<int> nums = {2, 3, 5,6};

    Solution a;
    int res =0;
    res = a.searchInsert(nums, 5);
    printf("5 res : %d\n", res);
    res = a.searchInsert(nums, 2);
    printf("2 res : %d\n", res);
    res = a.searchInsert(nums, 7);
    printf("7 res : %d\n", res);
    res = a.searchInsert(nums, 1);
    printf("1 res : %d\n", res);
    res = a.searchInsert(nums, 4);
    printf("4 res : %d\n", res);
}